<?php

require_once(drupal_get_path('module','gc_filters').'/classes/proto/GcBaseFilter.class.php');

class GcProducerFilter extends GcBaseFilter {
    
  const filterPathId = 'gcfProd';
  const filterDatabaseTableName    = 'content_type_product';
  const filterDatabaseColumnName   = 'field_producent_value';
  
  private $_filterValue;
  
  public function __construct() {
    $this->getFilterValue();
  }
  
  public function getFilterDatabaseQuery($bootstrap) {
    $responce = '';
    
    switch($bootstrap) {
      case 'where':
        $responce =  $this->prepareFilterWhereQuery();
      break;
      case 'value':
        $responce = $this->_filterValue;
      break;
      case 'join':
        $responce = $this->getFilterTableName();
      break;
        
    };
    return $responce;
  }

  protected function getFilterValue() {
    $this->_filterValue = $_GET[self::filterPathId];
  }
  
  protected function getFilterTableName() {
    return self::filterDatabaseTableName;
  }
  
  protected function prepareFilterWhereQuery() {
    
    $columnName = self::filterDatabaseColumnName;
    $tableName = $this->getFilterTableName();
    $query = '';     
    $query .= " ".$tableName.".".$columnName." = '%s' ";
    return $query;
  
  }
  
  public function isActive() {
  	if(isset($_GET[self::filterPathId]) && $_GET[self::filterPathId]) {
  		return  true;
  	} else {
  		return false;
  	}
  }
}